<template>
  <basic-container :btnFlag=true>
    <div class="card-border" style="padding-bottom: 28px;">
      <card-header :header-data="headerData"></card-header>
      <el-form
        label-width="130px"
        :model="releaseForm"
        style="padding-right: 30px;margin-top:12px;"
        :rules="reviewRules"
        ref="releaseForm"
      >
        <el-row>
          <el-col :span="22">
            <el-form-item class="form-item-release" label="发文名称 :" prop="releaseTitle">
              <el-input
                v-model="releaseForm.releaseTitle"
                placeholder="请输入发文名称"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item class="form-item-release" label="文号 :" prop="releaseNo">
              <el-input
                v-model="releaseForm.releaseNo"
                placeholder="请输入文号"
                style="width: 280px"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item class="form-item-release" label="发文单位 :" prop="releaseDeptName">
              <el-input
                v-model="releaseForm.releaseDeptName"
                placeholder="请输入发文单位"
                style="width: 280px"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item class="form-item-release" label="发文日期 :" prop="releaseFileDate">
              <el-date-picker
                style="width: 100%"
                v-model="releaseForm.releaseFileDate"
                type="date"
                placeholder="选择日期时间"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item class="form-item-release" label="正文附件 :">
              <el-upload
                class="upload-demo"
                action="string"
                :http-request="fileUploadRequest"
                :on-preview="fileHandlePreview"
                :on-remove="fileHandleRemove"
                :limit="1"
                :on-exceed="tipFileOne"
                :file-list="fileTypeIds['正文附件']"
                :auto-upload="true">
                <el-button slot="trigger" size="small" type="primary">点击上传</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22">
            <el-col :span="20">
              <el-form-item class="form-item-release" label="拟发布范围" prop="openScope" v-if="openScopeView">
                <el-select
                  v-model="releaseForm.openScope"
                  placeholder="请选择"
                  style="width: 280px;"
                >
                  <el-option
                    v-for="item in publishDIC"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22">
            <el-form-item class="form-item-release" label="规划文本:" prop="txt" :required="true" v-if="txtView">
              <el-upload
                class="upload-demo"
                ref="upload"
                :limit="1"
                :on-exceed="tipFileOne"
                action="string"
                :http-request="submitUploadtextMixin"
                :on-preview="handlePreviewtextMixin"
                :on-remove="handleRemovetextMixin"
                :file-list="fileListtextMixin"
                :auto-upload="true"
                :on-change="fileChangetextMixin">
                <el-button slot="trigger" size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">请上传规划文本</div>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22">
            <el-form-item class="form-item-release" label="规划文本(部分公开):" prop="txtHalfOpen" :required="true"
                          v-if="txtHalfOpenView">
              <el-upload
                class="uploadFile"
                action="string"
                :limit="1"
                :on-exceed="tipFileOne"
                :http-request="basisSubmitUploadMixin"
                :on-change="basisFileChangeMixin"
                :on-preview="basishandlePreviewMixin"
                :on-remove="basishandleRemoveMixin"
                :auto-upload="true"
                :file-list="basisFileListMixin">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip" style="margin-top: -8px;">请上传规划文本(部分公开)</div>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div class="form-submit" v-if="!stateFlag">
        <el-button type="warning" :disabled="isDisabled" @click.stop="publishReview()">发布</el-button>
      </div>
      <div class="form-submit" v-if="stateFlag == 'record'">
        <el-button type="warning" @click.stop="recordReviewClick()">报备</el-button>
      </div>
      <el-collapse v-model="activeNames" style="margin-top:2rem;">
        <el-collapse-item name="0" v-if="reviewDetailDataView">
          <template slot="title">
            <div class="card-header collapse-header">
              <div class="head-title collapse-title">审批详情</div>
            </div>
          </template>
          <div class="searchDetail">
            <bostech-detail :detail-data="reviewDetailData"></bostech-detail>
          </div>
        </el-collapse-item>
        <el-collapse-item name="1">
          <template slot="title">
            <div class="card-header collapse-header">
              <div class="head-title collapse-title">规划信息</div>
            </div>
          </template>
          <div class="searchDetail">
            <achievement-detail :id="achievementIdTemp"></achievement-detail>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
  </basic-container>
</template>
<script>
  import getReviewDetail from "@/mixins/review/getReviewDetail";
  import {offlineReview, recordReview, reviewRegDetail} from "@/api/review";
  import getDetailData from "@/mixins/getDetailData";
  import {getfileinfopage} from "@/api/system";
  import {resultDetail} from "@/api/planning/result";
  import fileTypeMixin from "@/mixins/fileTypeMixin";
  import {REVIEW_DIC} from "@/const/dict";
  import textfile from "@/mixins/textfile";
  import basisfile from "@/mixins/basisfile";
  import achievementDetail from "@/components/achievement/detail"

  export default {
    name: "reviewDetail",
    mixins: [getDetailData(), getReviewDetail(), fileTypeMixin, textfile,basisfile],
    components:{
      achievementDetail
    },
    data() {
      return {
        headerData: {
          title: '审批发布'
        },
        activeNames: ["0", "1"],
        pmuc: '',
        releaseForm: {
          txt: null,
          txtHalfOpen: null,
        },
        fileType: '正文附件',
        reviewRules: {
          releaseNo: [
            {required: true, message: "请输入文号", trigger: "blur"}
          ],
          releaseTitle: [
            {required: true, message: "请输入发文名称", trigger: "blur"}
          ],
          releaseDeptName: [
            {required: true, message: "请输入发文单位", trigger: "blur"}
          ],
          releaseFileDate: [
            {required: true, message: "请输入发文日期", trigger: "blur"}
          ],
          openScope: [
            {required: true, message: "请选择拟发布范围", trigger: "blur"}
          ],
        },
        isDisabled: false,
        // 发布方式字典
        publishDIC: REVIEW_DIC.publishDIC,
        projectForm: {
          textId: null,
          basisFileId: null,
        },
        txtHalfOpenView: false,
        txtView: false,
        openScopeView: false,
        reviewDetailDataView: true,
        achievementIdTemp:null
      };
    },
    created() {
      this.achievementIdTemp = Number(this.$route.query.achievementId);
      this.taskId = this.$route.query.taskId;
      this.stateFlag = this.$route.query.stateFlag;
      this.getDetailData();
      this.getDetailData_review(this.$route.params.id);
      if (this.$route.query.planningRank != undefined) {
        if (this.$route.query.planningRank == 'C') {
          this.openScopeView = true;
          this.txtView = true;
          this.reviewDetailDataView = false;
        }
      }
    },
    watch: {
      'releaseForm.openScope'(val) {
        if (val == '1') {
          this.txtHalfOpenView = true;
        } else {
          this.txtHalfOpenView = false;
        }
      },
      'projectForm.textId'(val) {
        if (val != null) {
          this.releaseForm.txt = this.projectForm.textId
        }
      },
      'projectForm.basisFileId'(val) {
        if (val != null) {
          this.releaseForm.txtHalfOpen = this.projectForm.basisFileId
        }
      },
    },
    methods: {
      // 获取规划详情信息
      getDetailData() {
        reviewRegDetail(this.taskId).then(response => {
          resultDetail(response.data.data.achievementId).then(response => {
            this.getresultDetail(response);
          })
        })
      },
      async getresultDetail(response) {
        if (response.data.code == '0') {
          var records = response.data.data;
          if (records.fileId != "" && records.fileId != null) {
            this.multiplefiles = [];
            this.multiplefiles = await this.getfileinfopagetemp(records);
          }
          this.pmuc = records.pmuc;
          this.getresultDetailDate(records)
        }
      },
      getfileinfopagetemp(records) {
        return new Promise((resolve, reject) => {
          if (records.fileId != "" && records.fileId != null) {
            getfileinfopage(Object.assign({
              current: 1,
              size: 100,
              fileIds: records.fileId
            })).then(response => {
              var multiplefiles = response.data.data.records;
              resolve(multiplefiles);
            }).catch(
            )
          }
        })
      },
      //线下流程确认
      publishReview() {
        this.$refs.releaseForm.validate(valid => {
          if (valid) {
            this.$confirm("确定发布么?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              this.releaseForm.txt = this.projectForm.textId;
              this.releaseForm.txtHalfOpen = this.projectForm.basisFileId;
              this.releaseForm.releaseFileId = this.getFileId(this.fileTypeIds[this.fileType]);
              this.isDisabled = true;
              offlineReview(this.taskId, this.releaseForm).then(response => {
                if (response.data.code == 0) {
                  this.$notify({
                    title: '成功',
                    message: '提交成功',
                    type: 'success',
                    duration: 2000
                  });
                  this.$router.go(-1);
                }
              })
            });
          } else {
            this.isDisabled = false;
          }
        });

        this.isDisabled = false;
      },
      // 报备
      recordReviewClick() {
        this.recordReview(this.taskId)
      },
      // 报备
      recordReview(taskId) {
        this.$confirm("确定报备么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          recordReview(taskId).then(response => {
            if (response.data.code == 0) {
              this.$notify({
                title: '成功',
                message: '报备成功',
                type: 'success',
                duration: 2000
              });
              this.$router.go(-1);
            }
          })
        })
      },
    }
  };
</script>

<style lang="scss" scoped>

</style>
